from airflow.sdk import Variable,dag, task
import pendulum
from airflow.operators.python import get_current_context




@dag(
    schedule=None,
    start_date=pendulum.datetime(2021, 1, 1, tz="UTC"),
    catchup=False, # 是否开启回填
    tags=["example"],
)
def hello_variable():
    """
    hello variable
    """

    @task
    def get_variable():
        """
        get variable 
        """
        appid = Variable.get("appid")
        print(f"the variable appid is {appid}")

    @task
    def get_currnet_time():
        """
        获取任务运行时间
        """
        context = get_current_context()
        execution_date = context['ds']
        print(f"Execution date is: {execution_date}")
    t1 = get_variable()
    t2 = get_currnet_time()
    t1 >> t2
hello_variable()